Skip to content

[Minor]: support window functions in order by expressions#20963

Open
buraksenn wants to merge 2 commits intoapache:mainfrom
buraksenn:support-window-functions-in-order-by
Open

[Minor]: support window functions in order by expressions#20963
buraksenn wants to merge 2 commits intoapache:mainfrom
buraksenn:support-window-functions-in-order-by

Conversation

@buraksenn
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

#608 has details but as @alamb describes in #608 (comment)

SELECT c2
  FROM test
  ORDER BY max(c3) OVER (ORDER BY c9);

fails with:

This feature is not implemented: Physical plan does not support logical expression WindowFunction(WindowFunction { fun: AggregateUDF(AggregateUDF { inner: Max { signature: Signature { type_signature: UserDefined, volatility: Immutable, parameter_names: None } } }), params: WindowFunctionParams { args: [Column(Column { relation: Some(Bare { table: "test" }), name: "c3" })], partition_by: [], order_by: [Sort { expr: Column(Column { relation: Some(Bare { table: "test" }), name: "c9" }), asc: true, nulls_first: false }], window_frame: WindowFrame { units: Range, start_bound: Preceding(Int32(NULL)), end_bound: CurrentRow, is_causal: false }, filter: None, null_treatment: None, distinct: false } })

What changes are included in this PR?

  • relevant change
  • slt and unit tests

Are these changes tested?

Yes added both unit tests for plan and slt tests for checking output

Are there any user-facing changes?

Additive user changes that users can now use window in order by expressions

@github-actions github-actions bot added sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels Mar 16, 2026
Copy link
Contributor

@haohuaijin haohuaijin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @buraksenn and @haohuaijin -- this also looks good to me

I had one suggestion / request for the test but otherwise looks good

fyi @jonahgao as our resident SQL planner expert in case you have time to review as well

@@ -0,0 +1,91 @@
# Licensed to the Apache Software Foundation (ASF) under one
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding a new test file, can you please integrate this into one of the existing files (window.slt or orderby.slt perhaps?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking since it is a new feature and intersection I can create a test file will do of course. I've moved them to window.slt. Thanks for the review @alamb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for window functions in order by expression

3 participants